home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / C Internet Config / IC Application Source ƒ / C Source ƒ / IC FSSpec Whats.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  3.9 KB  |  176 lines  |  [TEXT/SPM ]

  1. /*
  2.     IC FSSpec Whats.c
  3.     
  4. */
  5.  
  6. #include <Folders.h>
  7. #include <Aliases.h>
  8.  
  9. #include "IC Window Globals.h"
  10. #include "IC Types.h"
  11. #include "IC Dialogs.h"
  12. #include "IC Misc Subs.h"
  13. #include "IC Subs.h"
  14. #include "IC API.h"
  15. #include "IC Document.h"
  16. #include "IC Keys.h"
  17. #include "IC Globals.h"
  18. #include "IC StandardFile.h"
  19.  
  20. #include "IC FSSpec Whats.h"
  21.  
  22. OSErr ICGetVolumeStuff(StringPtr name,long date,short* vrn){
  23.     OSErr err;
  24.     HParamBlockRec pb;
  25.     Str255 s;
  26.     short i,pass;
  27.     
  28.     for (pass=1;pass<3;pass++){
  29.         i=1;
  30.         while (1){
  31.             pb.volumeParam.ioVolIndex=i;
  32.             i++;
  33.             pb.volumeParam.ioNamePtr=s;
  34.             s[0]=0;
  35.             err=PBHGetVInfoSync(&pb);
  36.             if (err!=noErr)
  37.                 return err;
  38.             if (IUEqualString(name,s)==0){
  39.                 if ((pass==2)||(pb.volumeParam.ioVCrDate==date))
  40.                     break;
  41.             }
  42.         }
  43.         
  44.         if (err==noErr)
  45.             break;
  46.     }
  47.     
  48.     if (err==noErr)
  49.         *vrn=pb.volumeParam.ioVRefNum;
  50.     
  51.     return err;
  52. }
  53.  
  54. OSErr WhatOpenFSSpec(WindowType wt,short item){
  55.     Handle spec=(Handle)0;
  56.     Boolean valid=false;
  57.     long loe;
  58.     Boolean changed;
  59.     long attr;
  60.     CInfoPBRec pb;
  61.     Boolean modified=false;
  62.     FSSpec fs;
  63.     ICFileSpecHandle sh;
  64.     
  65.     if (ICGetPrefHandle(GetInstance(),WindowInfo[wt].items[item]->key,&attr,&spec)==noErr)
  66.         valid=true;
  67.     
  68.     ProcessAttributes(wt,item,attr);
  69.     
  70.     if ((valid)&&(GetHandleSize(spec)<sizeof(ICFileSpec)))
  71.         valid=false;
  72.     
  73.     if (valid){
  74.         sh=(ICFileSpecHandle)spec;
  75.         
  76.         if (((*sh)->alias.aliasSize==0)||(!Has_AliasMgr)){
  77.             if (ICGetVolumeStuff((*sh)->vol_name,(*sh)->vol_creation_date,&fs.vRefNum)==noErr){
  78.                 fs.parID=(*sh)->fss.parID;
  79.                 SetPString(fs.name,1,(*sh)->fss.name);
  80.                 
  81.                 if (ICFSpGetCatInfo(&fs,0,&pb)!=noErr){
  82.                     modified=true;
  83.                     valid=false;
  84.                 }
  85.             } else
  86.                 valid=false;
  87.         } else {
  88.             Munger(spec,0,(Ptr)0,sizeof(ICFileSpec)-sizeof(AliasRecord),(Ptr)&loe,0);
  89.             if (ResolveAlias(nil,(AliasHandle)spec,&fs,&changed)!=noErr){
  90.                 modified=true;
  91.                 valid=false;
  92.             }
  93.         }
  94.     }
  95.     if (!valid){
  96.         if ((FindFolder(kOnSystemDisk,kDesktopFolderType,true,&fs.vRefNum,&fs.parID)==noErr)&&(ICFSpGetCatInfo(&fs,-1,&pb)==noErr)){
  97.             fs.vRefNum=pb.dirInfo.ioVRefNum;
  98.             fs.parID=pb.dirInfo.ioDrParID;
  99.         } else {
  100.             fs.vRefNum=0;
  101.             fs.parID=0;
  102.             fs.name[0]=0;
  103.         }
  104.     }
  105.     
  106.     DisposeHandle(spec);
  107.     BlockMoveData((Ptr)&fs,(Ptr)&(WindowInfo[wt].items[item]->fss),sizeof(FSSpec));
  108.     WindowInfo[wt].items[item]->modified=modified;
  109.     SetDCtlTitle(WindowInfo[wt].window,item,fs.name);
  110.     SetDCtlEnable(WindowInfo[wt].window,item,!IsLocked(wt,item));
  111.     
  112.     return noErr;
  113. }
  114.  
  115. OSErr WhatClickFSSpec(WindowType wt,short item,EventRecord* er){
  116.     OSErr err;
  117.     FSSpec fs;
  118.     long dirID;
  119.     
  120.     err=ICStandardGetFolder(&fs,&dirID);
  121.     if (err==noErr){
  122.         DirtyDocument();
  123.         WindowInfo[wt].items[item]->fss.vRefNum=fs.vRefNum;
  124.         WindowInfo[wt].items[item]->fss.parID=dirID;
  125.         WindowInfo[wt].items[item]->fss.name[0]=0;
  126.         
  127.         SetDCtlTitle(WindowInfo[wt].window,item,fs.name);
  128.     }
  129.     return err;
  130. }
  131.  
  132. OSErr WhatFlushFSSpec(WindowType wt,short item){
  133.     AliasHandle alias;
  134.     ICFileSpec ifs;
  135.     HParamBlockRec pb;
  136.     OSErr err=noErr;
  137.     long pos;
  138.     
  139.     if (!IsLocked(wt,item)){
  140.         BlockMoveData((Ptr)&(WindowInfo[wt].items[item]->fss),&ifs.fss,sizeof(FSSpec));
  141.         alias=(AliasHandle)0;
  142.         err=(OSErr)-1;
  143.         if (Has_AliasMgr)
  144.             err=NewAlias((FSSpec*)0,&ifs.fss,&alias);
  145.         if (err!=noErr){
  146.             alias=(AliasHandle)NewHandle(sizeof(AliasRecord));
  147.             err=MemError();
  148.             if (err==noErr){
  149.                 (*alias)->aliasSize=0;
  150.                 (*alias)->userType=(OSType)0;
  151.             }
  152.         }
  153.         if (err==noErr){
  154.             pb.volumeParam.ioVRefNum=ifs.fss.vRefNum;
  155.             pb.volumeParam.ioVolIndex=0;
  156.             pb.volumeParam.ioNamePtr=ifs.vol_name;
  157.             err=PBHGetVInfoSync(&pb);
  158.             if (err==noErr)
  159.                 ifs.vol_creation_date=pb.volumeParam.ioVCrDate;
  160.         }
  161.         
  162.         if (err==noErr){
  163.             Munger((Handle)alias,0,(Ptr)0,0,(Ptr)&ifs,sizeof(ICFileSpec)-sizeof(AliasRecord));
  164.             err=MemError();
  165.         }
  166.         
  167.         if (err==noErr)
  168.             err=ICMapErr(ICSetPrefHandle(GetInstance(),WindowInfo[wt].items[item]->key,ICattr_no_change,(Handle)alias));
  169.         
  170.         if (alias!=(AliasHandle)0)
  171.             DisposeHandle((Handle)alias);
  172.     }
  173.     
  174.     return err;
  175. }
  176.